package com.system.employment.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.system.common.util.ExtAjaxResponse;
import com.system.common.util.ExtPageable;
import com.system.employment.entity.Employment;
import com.system.employment.entity.dto.EmploymentQueryDTO;
import com.system.employment.service.IEmploymentService;

@Controller
@RequestMapping("/employment")
public class EmploymentController {
	@Autowired
	private IEmploymentService employmentService;
	
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(Employment employment) {
		try {
			employmentService.saveOrUpdate(employment);
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	}
	
	@RequestMapping("/delete")
	public @ResponseBody ExtAjaxResponse delete(Long id) {
		try {
			Employment employment=employmentService.findOne(id);
			if(null!=employment) {
				employmentService.delete(employment);
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	}
	
	@RequestMapping("/deleteEmployments")
	public @ResponseBody ExtAjaxResponse deleteEmployments(@RequestParam Long[] ids) {
		try {
			List<Long> lists=Arrays.asList(ids);
			if(null!=lists) {
				employmentService.delete(lists);
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	}
	
	@RequestMapping("/findOne")
	public @ResponseBody Employment findOne(@RequestParam Long id) 
	{
		Employment employment =  employmentService.findOne(id);
		
		return employment;
	}
	
	@RequestMapping("/findAll")
	public @ResponseBody List<Employment> findAll() 
	{
		 List<Employment> lists =  employmentService.findAll();
		
		return lists;
	}
	
	@RequestMapping("/findPage")
	public @ResponseBody Page<Employment> findPage(EmploymentQueryDTO employmentDTO,ExtPageable pageable) 
	{
		Page<Employment> page =  employmentService.findAll(EmploymentQueryDTO.getSpecification(employmentDTO), pageable.getPageable());
		return page;
	}
}
